/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frm.billingAndPaymentProcessing.managedbean;

import crm.clientManagement.entity.CompanyEntity;
import crm.salesOrderProcessing.entity.DeliveryOrderEntity;
import crm.salesOrderProcessing.entity.LineItemEntity;
import frm.billingAndPaymentProcessing.entity.InvoiceEntity;
import frm.billingAndPaymentProcessing.session.InvoiceSessionBean;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import crm.salesOrderProcessing.session.DeliveryOrderSessionBean;

/**
 *
 * @author xhx
 */
@ManagedBean
@ViewScoped
public class InvoiceCreationResultManagedBean {
private InvoiceEntity invoice;
private CompanyEntity company;
private DeliveryOrderEntity deliveryOrder;
private List<LineItemEntity> lineItemList;

@EJB
InvoiceSessionBean invoiceSessionBean;
@EJB
DeliveryOrderSessionBean deliveryOrderSessionBean;

    
    /** Creates a new instance of InvoiceCreationResultManagedBean */
    public InvoiceCreationResultManagedBean() {
    }

    public void initView(PhaseEvent event) {
        if (invoice == null) {
            setInvoice((InvoiceEntity) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("invoice"));
        }
        
        deliveryOrder = invoice.getDeliveryOrder();
        
        lineItemList = deliveryOrder.getLineItems();
        company = deliveryOrder.getParentSalesOrder().getCustomer();
    }
    
    public List<DeliveryOrderEntity> formDeliveryOrderList(){
        List<DeliveryOrderEntity> dOrderList = new ArrayList<DeliveryOrderEntity>();
        dOrderList.add(deliveryOrder);
        return dOrderList;
    }
    public void viewRecord() throws IOException{
           
           FacesContext.getCurrentInstance().getExternalContext().getFlash().put("invoice", invoice);
          FacesContext.getCurrentInstance().getExternalContext().redirect("displayInvoice.xhtml");
    
    }
    
    public InvoiceEntity getInvoice() {
        return invoice;
    }

    public void setInvoice(InvoiceEntity invoice) {
        this.invoice = invoice;
    }

    public CompanyEntity getCompany() {
        return company;
    }

    public void setCompany(CompanyEntity company) {
        this.company = company;
    }

    public DeliveryOrderEntity getDeliveryOrder() {
        return deliveryOrder;
    }

    public void setDeliveryOrder(DeliveryOrderEntity deliveryOrder) {
        this.deliveryOrder = deliveryOrder;
    }

    public List<LineItemEntity> getLineItemList() {
        return lineItemList;
    }

    public void setLineItemList(List<LineItemEntity> lineItemList) {
        this.lineItemList = lineItemList;
    }
}
